import axios from "axios"
//引入elementui Loading 
import { Loading } from "element-ui";
//配置loading样式，不配置就是默认样式
const options = {
    text: '加载中',
    background: 'rgba(0, 0, 0, 0.7)'
}
//引入nprogrss
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
//二次封装axios
const request = axios.create({
    baseURL: '/api-github',
    timeout: 2 * 1000
})
//请求拦截器
request.interceptors.request.use((config) => {
    NProgress.start();
    //打开遮罩层loading
    Loading.service(options);
    return config
})
// 响应拦截器
request.interceptors.response.use((response) => {
    NProgress.done();
    //关闭遮罩层loading
    Loading.service(options).close();
    return response.data
}, (error) => {
    NProgress.done();
    //关闭遮罩层loading
    Loading.service(options).close();
    return Promise.reject('请求失败')
})

export default request